package GUI_Data.User;

import Data_Flow.GetData;
import Data_Structure.DataImplement.Flight;
import Data_Structure.DataImplement.MealAndPrice;
import GUI_Data.FlightSeatPanel.AirbusA320Panel;
import GUI_Data.FlightSeatPanel.Boeing737Panel;
import GUI_Data.FlightSeatPanel.FlightSeatPanel;
import lombok.Data;

import javax.swing.*;
import java.awt.*;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Set;

/**
 * This class contains all the labels and the process to add components to container.
 * @author Xiaorun Wang
 * @author Chunxi Lin
 * @author Yibai Jiang
 */
@Data
public class AllPanel {
    private FlightSeatPanel flightSeatPanel;
    private FlightSeatPanel extraFlightSeatPanel;

    private MealAndPrice.Meals[] mealsName;
    int[] mealsPrice;
    private JRadioButton[] mealsChooseBoxes;
    private ButtonGroup mealChooseGroup = new ButtonGroup();
    private int[] mealsChooseNum;

    private MealAndPrice.Meals[] extraMealsName;
    private int[] extraMealsPrice;
    private JComboBox[] extraMealsChooseNumBoxes;
    private int[] extraMealsChooseNum;

    private final JProgressBar progressBar = new JProgressBar();
    private final JProgressBar progressBarPay = new JProgressBar();
    private int MIN_PROGRESS = 0;
    private int MAX_PROGRESS = 100;
    private int currentProgress = MIN_PROGRESS;

    private JPanel contentPanel = new JPanel();

    private JPanel headerPanel = new JPanel(new FlowLayout());

    private JPanel footingPanel = new JPanel(new FlowLayout());

    private JPanel toLast = new JPanel();

    private JPanel toNext = new JPanel();

    private JPanel centerPanel;

    private JPanel originPanel = new JPanel(new BorderLayout());

    private JPanel bookedPanel = new JPanel(new GridLayout(AllData.bookedNum + 1,1));

    private JPanel rowOne = new JPanel(new GridLayout(1,10));
    private JPanel rowTwo = new JPanel(new GridLayout(1,10));
    private JPanel rowThree = new JPanel(new GridLayout(1,9));
    private JPanel rowFour = new JPanel(new GridLayout(1,9));
    private JPanel keyboardPanel = new JPanel(new GridLayout(4,1));

    private JPanel rowOne2 = new JPanel(new GridLayout(1,10));
    private JPanel rowTwo2 = new JPanel(new GridLayout(1,10));
    private JPanel rowThree2 = new JPanel(new GridLayout(1,9));
    private JPanel rowFour2 = new JPanel(new GridLayout(1,9));
    private JPanel keyboardPanel2 = new JPanel(new GridLayout(4,1));

    private JPanel loginPanel = new JPanel(new GridLayout(2,1));

    private JPanel inputPanel;

    private JPanel numPanel = new JPanel(new FlowLayout());

    private JPanel clickPanel = new JPanel (new GridLayout(2,1));
    private JPanel buttonPanel = new JPanel(new FlowLayout());
    private JPanel helpPanel = new JPanel(new FlowLayout());

    private JPanel idPanel1 = new JPanel(new FlowLayout());

    private JPanel scanPanel = new JPanel();

    private JPanel payPanel = new JPanel();
    private JPanel payInformationPanel;
    private JScrollPane payTablePanel;
    private JPanel payButton;

    private JPanel printingPanel = new JPanel(new GridLayout(1,1));
    private JPanel printPanel = new JPanel(new GridLayout(4,1));
    private JPanel buttonPanelInPrintPanel = new JPanel();

    private JPanel printTablePanel = new JPanel();
    private JPanel passPanel = new JPanel(new GridLayout(1,2));
    private JPanel bagPanel = new JPanel(new GridLayout(1,2));
    private JPanel ticketPanel = new JPanel(new GridLayout(1,2));

    private JPanel printWord = new JPanel(new FlowLayout());
    private JPanel printStyle = new JPanel(new GridLayout(3,1));
    private JPanel printButtonPanel = new JPanel(new FlowLayout());

    private JPanel payWord = new JPanel(new FlowLayout());
    private JPanel payStyle = new JPanel(new GridLayout(3,1));
    private JPanel payButtonPanel = new JPanel(new FlowLayout());

    private JPanel displayPanel = new JPanel(new BorderLayout(10,10));
    private JPanel informationPanel = new JPanel();

    private JPanel information = new JPanel(new GridLayout(7,1));
    private JPanel next = new JPanel(new FlowLayout());

    private JPanel seatChoosePanel = new JPanel(new BorderLayout());
    private JPanel buttonListInSeatChoose = new JPanel();

    private JPanel mealChoosePanel = new JPanel(new BorderLayout());
    private JPanel mealPanel = new JPanel();
    private JPanel buttonListInMealChoose = new JPanel();

    private JPanel extraSeatChoosePanel = new JPanel(new BorderLayout());
    private JPanel buttonListInExtraSeatChoose = new JPanel();

    private JPanel extraMealChoosePanel = new JPanel(new BorderLayout());
    private JPanel extraMealPanel = new JPanel();
    private JPanel buttonListInExtraMealChoose = new JPanel();

    /**
     * The generator of AllPanel.
     * Initialize all panels and complete the process of adding components to the container.
     * @param nowFrame User interface currently displayed (will be replaced after reset).
     * @param dimension All the dimension information.
     * @param allButton All the Button objects.
     * @param allLabelAndTextField All the JLabel and JTextField objects.
     * @param card The CardLayout object of the center panel.
     * @param login The CardLayout object of the input panel in login page.
     */
    public AllPanel(JPanel nowFrame,SetDimension dimension,AllButton allButton,AllLabelAndTextField allLabelAndTextField,CardLayout card,CardLayout login){

        /* Set the page header. */
        headerPanel.setPreferredSize(dimension.getHeaderDimension());
        headerPanel.setBorder(AllBorder.panelBorder);
        headerPanel.setOpaque(false);
        headerPanel.add(allButton.getExitButton());
        headerPanel.add(allButton.getBackToOrigin());
        headerPanel.add(allButton.getBackToSeatChoose());
        headerPanel.add(allButton.getBackToMealChoose());
        headerPanel.add(allButton.getBackToDisplay());
        headerPanel.add(allButton.getBackToPay());
        headerPanel.add(allButton.getBackToPrinting());

        /* Set the page footing. */
        footingPanel.setPreferredSize(dimension.getFootingDimension());
        footingPanel.setBorder(AllBorder.panelBorder);
        contentPanel.setOpaque(false);

        /* Set the left sidebar. */
        toLast.setPreferredSize(dimension.getSidebarDimension());
        toLast.setBorder(AllBorder.panelBorder);
        toLast.add(allButton.getLastButton());
        //     add(toLast,BorderLayout.WEST);

        /* Set the right sidebar. */
        toNext.setPreferredSize(dimension.getSidebarDimension());
        toNext.setBorder(AllBorder.panelBorder);
        toNext.add(allButton.getNextButton());
        //    add(toNext,BorderLayout.EAST);

        /* Set center page. */
        centerPanel = new JPanel(card);
        centerPanel.setBorder(AllBorder.panelBorder);
        centerPanel.setPreferredSize(dimension.getCenterDimension());
        centerPanel.setOpaque(false);

        /* Set the origin page. */
//        originPanel.setBorder(panelBorder);
//        JLabel originLabel = new JLabel("Origin Page!");
//        originPanel.add(originLabel, BorderLayout.NORTH);
        originPanel.setOpaque(false);
        centerPanel.add("Origin page",originPanel);

        /* set booked flights displaying page */
        bookedPanel.add(allLabelAndTextField.getAmount());
        centerPanel.add("booked page",bookedPanel);

        /* set keyboard panel */
        keyboardPanel.add(rowOne);
        keyboardPanel.add(rowTwo);
        keyboardPanel.add(rowThree);
        keyboardPanel.add(rowFour);
        keyboardPanel.setPreferredSize(dimension.getKeyDimension());
        keyboardPanel2.add(rowOne2);
        keyboardPanel2.add(rowTwo2);
        keyboardPanel2.add(rowThree2);
        keyboardPanel2.add(rowFour2);
        keyboardPanel2.setPreferredSize(dimension.getKeyDimension());
        for(int i = 26; i < 36; i ++){
            rowOne.add(allButton.getKeyboard1()[i]);
            rowOne2.add(allButton.getKeyboard2()[i]);
        }
        for(int i = 0; i < 10; i ++){
            rowTwo.add(allButton.getKeyboard1()[i]);
            rowTwo2.add(allButton.getKeyboard2()[i]);
        }
        for(int i = 10; i < 19; i ++){
            rowThree.add(allButton.getKeyboard1()[i]);
            rowThree2.add(allButton.getKeyboard2()[i]);
        }
        rowFour.add(allButton.getCapsLock());
        rowFour2.add(allButton.getCapsLock2());
        for(int i = 19; i < 26; i ++){
            rowFour.add(allButton.getKeyboard1()[i]);
            rowFour2.add(allButton.getKeyboard2()[i]);
        }
        rowFour.add(allButton.getOriginDelete());
        rowFour2.add(allButton.getOriginDelete2());

        keyboardPanel.setPreferredSize(new Dimension(1000,200));
        keyboardPanel2.setPreferredSize(new Dimension(1000,200));

        /* set login page */
        inputPanel = new JPanel(login);
        inputPanel.setPreferredSize(dimension.getInputDimension());
        inputPanel.setOpaque(false);
        numPanel.add(allLabelAndTextField.getInput_bookingNum());
        numPanel.add(allLabelAndTextField.getNum());
        numPanel.add(keyboardPanel);
        inputPanel.add("booking number",numPanel);
        buttonPanel.add(allButton.getOriginBooking());
        buttonPanel.add(allButton.getOriginID());
        buttonPanel.add(allButton.getOriginScan());
        buttonPanel.setOpaque(false);
        helpPanel.add(allButton.getOriginConfirm());
        helpPanel.setOpaque(false);
        clickPanel.add(buttonPanel);
        clickPanel.add(helpPanel);
        clickPanel.setOpaque(false);
//        loginPanel.add(allLabelAndTextField.getInput(), BorderLayout.NORTH);
        loginPanel.add(inputPanel, BorderLayout.CENTER);
        //        loginPanel.add(keyboardPanel);
        loginPanel.add(clickPanel, BorderLayout.SOUTH);
        loginPanel.setOpaque(false);
        originPanel.add(loginPanel, BorderLayout.CENTER);

        /* set login page-ID */
        idPanel1.add(allLabelAndTextField.getInput_Sur_ID());
        idPanel1.add(allLabelAndTextField.getSur());
        idPanel1.add(allLabelAndTextField.getId());
        idPanel1.add(keyboardPanel2);
        inputPanel.add("sur and ID", idPanel1);

        /* set login page-Scan */
        scanPanel.add(allButton.getScanConfirm());
        inputPanel.add("scan",scanPanel);


        /* Set the display page. */
        displayPanel.setBorder(AllBorder.panelBorder);
        displayPanel.add(allLabelAndTextField.getDisplayLabel(), BorderLayout.NORTH);
        displayPanel.setOpaque(false);
        centerPanel.add("Display page",displayPanel);
        next.setPreferredSize(dimension.getDisplayDimension());
        next.add(allButton.getDisplaySeatChoose());
        next.add(allButton.getDisplayMealChoose());
        next.add(allButton.getCheckIn());

        information.add(allLabelAndTextField.getFlightNum());
        information.add(allLabelAndTextField.getStatus());
        information.add(allLabelAndTextField.getDepartTime());
        information.add(allLabelAndTextField.getDepartGate());
        information.add(allLabelAndTextField.getSeat());
        information.add(allLabelAndTextField.getCounter());
        information.add(allLabelAndTextField.getFood());
        information.setOpaque(false);
//        informationPanel.add(information);
//        informationPanel.setOpaque(false);
        displayPanel.add(information,BorderLayout.CENTER);
        displayPanel.add(next,BorderLayout.EAST);

        /* Set paying page. */
        centerPanel.add("Paying page",payPanel);

        /* Set printing page. */
        printingPanel.setBorder(AllBorder.panelBorder);
        printingPanel.setOpaque(false);
        centerPanel.add("Printing page",printingPanel);
        passPanel.add(allLabelAndTextField.getPass());
        passPanel.setOpaque(false);
        bagPanel.add(allLabelAndTextField.getBag());
        bagPanel.setOpaque(false);
        ticketPanel.add(allLabelAndTextField.getTicket());
        ticketPanel.setOpaque(false);
        buttonPanelInPrintPanel.add(allButton.getPrintAll());
        buttonPanelInPrintPanel.add(allButton.getPrintingBack());
//        printPanel.add(passPanel);
//        printPanel.add(bagPanel);
//        printPanel.add(ticketPanel);
        JPanel printInformationPanel = new JPanel(new BorderLayout());
        JScrollPane printTablePanel = new JScrollPane(allLabelAndTextField.getPrintTable());
        printTablePanel.setPreferredSize(dimension.getPayTableDimension());
        printInformationPanel.setPreferredSize(dimension.getPayInfoDimension());
        printInformationPanel.add(printTablePanel,BorderLayout.CENTER);
        printPanel.add(printInformationPanel);
        printPanel.add(buttonPanelInPrintPanel);
        printPanel.setOpaque(false);
        printingPanel.add(printPanel);

        /* set printStyle page */
        centerPanel.add("printStyle",printStyle);
        /* set payStyle page */

        /* set seat choose page */
        seatChoosePanel.setBorder(BorderFactory.createLineBorder(Color.black,1,true));
        seatChoosePanel.add(allLabelAndTextField.getSeatChooseLabel(),BorderLayout.NORTH);
        buttonListInSeatChoose.setPreferredSize(dimension.getButtonListInSeatChooseDimension());
        buttonListInSeatChoose.add(allButton.getButtonInSeatChooseConfirm());
        buttonListInSeatChoose.add(allButton.getButtonInSeatChooseCancelSelect());
        seatChoosePanel.add(buttonListInSeatChoose,BorderLayout.EAST);
        seatChoosePanel.setOpaque(false);
        centerPanel.add("Seat choose page",seatChoosePanel);


        /* set meal choose page */
        mealChoosePanel.setBorder(BorderFactory.createLineBorder(Color.black,1,true));

        buttonListInMealChoose.setPreferredSize(dimension.getButtonListInMealChooseDimension());
        mealChoosePanel.add(buttonListInMealChoose,BorderLayout.EAST);
        mealChoosePanel.setOpaque(false);
        centerPanel.add("Meal choose page",mealChoosePanel);
        buttonListInMealChoose.add(allButton.getButtonInMealChooseConfirm());
        buttonListInMealChoose.add(allButton.getButtonInMealChooseCancelSelect());
        buttonListInMealChoose.add(allButton.getButtonInMealChooseReturn());

        /* set extra seat choose page */
        extraSeatChoosePanel.setBorder(BorderFactory.createLineBorder(Color.black,1,true));
        extraSeatChoosePanel.add(allLabelAndTextField.getExtraSeatChooseLabel(),BorderLayout.NORTH);
        buttonListInExtraSeatChoose.setPreferredSize(dimension.getButtonListInSeatChooseDimension());
        extraSeatChoosePanel.add(buttonListInExtraSeatChoose,BorderLayout.EAST);
        extraSeatChoosePanel.setOpaque(false);
        centerPanel.add("Extra Seat choose page",extraSeatChoosePanel);
        buttonListInExtraSeatChoose.add(allButton.getButtonInExtraSeatChooseConfirm());
        buttonListInExtraSeatChoose.add(allButton.getButtonInExtraSeatChooseCancelSelect());
        buttonListInExtraSeatChoose.add(allButton.getButtonInExtraSeatChooseReturn());

        /* set extra meal choose page */
        extraMealChoosePanel.setBorder(BorderFactory.createLineBorder(Color.black,1,true));
        JScrollPane extraMealChooseJSP = new JScrollPane(extraMealPanel);
        extraMealChooseJSP.setPreferredSize(dimension.getMealChooseDimension());
        extraMealChooseJSP.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
        extraMealChooseJSP.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);
        extraMealChoosePanel.add(extraMealChooseJSP,BorderLayout.CENTER);
        buttonListInExtraMealChoose.setPreferredSize(dimension.getButtonListInMealChooseDimension());
        extraMealChoosePanel.add(buttonListInExtraMealChoose,BorderLayout.EAST);
        extraMealChoosePanel.setOpaque(false);
        centerPanel.add("Extra Meal choose page",extraMealChoosePanel);
        buttonListInExtraMealChoose.add(allButton.getButtonInExtraMealChooseConfirm());
        buttonListInExtraMealChoose.add(allButton.getButtonInExtraMealChooseCancelSelect());
        buttonListInExtraMealChoose.add(allButton.getButtonInExtraMealChooseReturn());

        nowFrame.add(headerPanel);
        nowFrame.add(centerPanel);
    }

    /**
     * This method is called when you log in using the second or third login methods.
     * Used to generate and add flight listings.
     * @param allLabelAndTextField All the JLabel and JTextField objects.
     */
    public void preInit(AllLabelAndTextField allLabelAndTextField){
        bookedPanel.add(new JScrollPane(allLabelAndTextField.getFlightTable()));
    }

    /**
     * This method is called after login and is used to generate pages for seat selection,
     * meal selection, upgrade and extra meal.
     * @param userFrame The user frame contains this class
     * @param dimension All the dimension information.
     * @param allButton All the Button objects.
     * @param getData The object to get data according to the login account.
     */
    public void init(UserFrame userFrame,SetDimension dimension,AllButton allButton,GetData getData){
        /* init seat choose page */
        if (getData.getMyPlaneType() == Flight.PlaneType.Boeing737)
            flightSeatPanel = new Boeing737Panel(userFrame,getData);
        else if (getData.getMyPlaneType() == Flight.PlaneType.AirbusA320)
            flightSeatPanel = new AirbusA320Panel(userFrame,getData);
        JScrollPane seatChooseJSP = new JScrollPane(flightSeatPanel);
        seatChooseJSP.setPreferredSize(dimension.getSeatChooseDimension());
        seatChooseJSP.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
        seatChooseJSP.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);
        seatChoosePanel.add(seatChooseJSP,BorderLayout.WEST);

        /* init meal choose page */
        ArrayList<HashMap<MealAndPrice.Meals,Integer>> mealsInfo = getData.getMealServerNumber();
        mealsName = new MealAndPrice.Meals[mealsInfo.size()];
        mealsPrice = new int[mealsInfo.size()];
        mealsChooseBoxes = new JRadioButton[mealsInfo.size()];
        mealsChooseNum = new int[mealsInfo.size()];
        for (int i = 0; i < mealsInfo.size(); i++) {
            HashMap<MealAndPrice.Meals,Integer> mealInfo = mealsInfo.get(i);
            Set<MealAndPrice.Meals> set = mealInfo.keySet();
            for ( MealAndPrice.Meals mealNameTemp : set ) {
                mealsName[i] = mealNameTemp;
                mealsPrice[i] = mealInfo.get(mealNameTemp);
            }
        }
        mealPanel.setPreferredSize(new Dimension((int)dimension.getEachMealPanelDimension().getWidth(),(int)dimension.getEachMealPanelDimension().getHeight()*mealsName.length));
        mealPanel.setLayout(new GridLayout(mealsName.length,1));
        mealPanel.setOpaque(false);
        for (int i = 0; i < mealsInfo.size(); i++) {
            JPanel eachMealPanel = new JPanel(new GridLayout(1,4));
            eachMealPanel.setPreferredSize(dimension.getEachMealPanelDimension());
            //Get meal image according to number
            JLabel mealImage = new JLabel();
            ImageIcon img = new ImageIcon("src/GUI_Data/Sources/MealPicture/0.jpg");
            img.setImage(img.getImage().getScaledInstance((int)dimension.getMealPictureDimension().getWidth(),(int)dimension.getMealPictureDimension().getHeight(),Image.SCALE_DEFAULT));
            mealImage.setIcon(img);
            //Get meal name according to number
            JLabel mealName = new JLabel(mealsName[i].toString());
            JLabel mealPrice = new JLabel(mealsPrice[i]+"");
            //Select the number of meal
            JRadioButton mealNumber = new JRadioButton();
            mealsChooseBoxes[i] = mealNumber;
            mealChooseGroup.add(mealsChooseBoxes[i]);
            eachMealPanel.add(mealImage);
            eachMealPanel.add(mealName);
            eachMealPanel.add(mealPrice);
            eachMealPanel.add(mealNumber);

            eachMealPanel.setBorder(BorderFactory.createLineBorder(Color.black,1,true));
            mealPanel.add(eachMealPanel);
        }
        mealsChooseBoxes[0].setSelected(true);
        JScrollPane mealChooseJSP = new JScrollPane(mealPanel);
        mealChooseJSP.setPreferredSize(dimension.getMealChooseDimension());
        mealChooseJSP.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
        mealChooseJSP.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);
        mealChoosePanel.add(mealChooseJSP,BorderLayout.CENTER);

        /* init extra seat choose page */
        if (getData.getMyPlaneType() == Flight.PlaneType.Boeing737)
            extraFlightSeatPanel = new Boeing737Panel(userFrame,getData,0);
        else if (getData.getMyPlaneType() == Flight.PlaneType.AirbusA320)
            extraFlightSeatPanel = new AirbusA320Panel(userFrame,getData,0);
        JScrollPane extraSeatChooseJSP = new JScrollPane(extraFlightSeatPanel);
        extraSeatChooseJSP.setPreferredSize(dimension.getSeatChooseDimension());
        extraSeatChooseJSP.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
        extraSeatChooseJSP.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);
        extraSeatChoosePanel.add(extraSeatChooseJSP,BorderLayout.WEST);

        /* init extra meal choose page */
        ArrayList<HashMap<MealAndPrice.Meals,Integer>> extraMealsInfo = getData.getMealServerNumber();
        extraMealsName = new MealAndPrice.Meals[extraMealsInfo.size()];
        extraMealsPrice = new int[extraMealsInfo.size()];
        extraMealsChooseNumBoxes  = new JComboBox[extraMealsInfo.size()];
        extraMealsChooseNum = new int[extraMealsInfo.size()];
        for (int i = 0; i < extraMealsInfo.size(); i++) {
            HashMap<MealAndPrice.Meals,Integer> mealInfo = extraMealsInfo.get(i);
            Set<MealAndPrice.Meals> set = mealInfo.keySet();
            for ( MealAndPrice.Meals mealNameTemp : set ) {
                extraMealsName[i] = mealNameTemp;
                extraMealsPrice[i] = mealInfo.get(mealNameTemp);
            }
        }
        extraMealPanel.setPreferredSize(new Dimension((int)dimension.getEachMealPanelDimension().getWidth(),(int)dimension.getEachMealPanelDimension().getHeight()*extraMealsName.length));
        extraMealPanel.setLayout(new GridLayout(extraMealsName.length,1));
        extraMealPanel.setOpaque(false);
        for (int i = 0; i < extraMealsInfo.size(); i++) {
            JPanel eachMealPanel = new JPanel(new GridLayout(1,4));
            eachMealPanel.setPreferredSize(dimension.getEachMealPanelDimension());
            //Get meal image according to number
            JLabel mealImage = new JLabel();
            ImageIcon img = new ImageIcon("src/GUI_Data/Sources/MealPicture/0.jpg");
            img.setImage(img.getImage().getScaledInstance((int)dimension.getMealPictureDimension().getWidth(),(int)dimension.getMealPictureDimension().getHeight(),Image.SCALE_DEFAULT));
            mealImage.setIcon(img);
            //Get meal name according to number
            JLabel mealName = new JLabel(extraMealsName[i].toString());
            JLabel mealPrice = new JLabel(extraMealsPrice[i]+"");
            //Select the number of meal
            JComboBox<Integer> mealNumber = new JComboBox<>();
            for (int j = 0; j < 11; j++) {
                mealNumber.addItem(j);
            }
            extraMealsChooseNumBoxes[i] = mealNumber;
            eachMealPanel.add(mealImage);
            eachMealPanel.add(mealName);
            eachMealPanel.add(mealPrice);
            eachMealPanel.add(mealNumber);

            eachMealPanel.setBorder(BorderFactory.createLineBorder(Color.black,1,true));
            extraMealPanel.add(eachMealPanel);
        }
    }

    /**
     * This method is called when going to the Pay Page to generate the Pay page and add components.
     * @param dimension All the dimension information.
     * @param allLabelAndTextField All the JLabel and JTextField objects.
     * @param allButton All the Button objects.
     */
    public void createPayPage(SetDimension dimension,AllLabelAndTextField allLabelAndTextField,AllButton allButton){
        centerPanel.remove(payPanel);
        payPanel = new JPanel(new BorderLayout());
        payInformationPanel = new JPanel(new BorderLayout());
        payButton = new JPanel(new FlowLayout());
        payPanel.setBorder(AllBorder.panelBorder);
        payPanel.setOpaque(false);
        centerPanel.add("Paying page",payPanel);
        payTablePanel = new JScrollPane(allLabelAndTextField.getPayTable());
        payTablePanel.setPreferredSize(dimension.getPayTableDimension());
        payInformationPanel.setPreferredSize(dimension.getPayInfoDimension());
        payInformationPanel.add(payTablePanel,BorderLayout.CENTER);
        payInformationPanel.add(allLabelAndTextField.getTotal(),BorderLayout.SOUTH);
        payInformationPanel.setOpaque(false);
        payButton.add(allButton.getPayPay());
        payButton.add(allButton.getPayCancel());
        payButton.setPreferredSize(dimension.getButtonPanelInPayHeightDimension());
        payButton.setOpaque(false);
        payPanel.add(payButton,BorderLayout.SOUTH);
        payPanel.add(payInformationPanel,BorderLayout.CENTER);
    }

    /**
     * This method will be called when paying, to show the paying process.
     * @param allButton All the Button objects.
     * @param allLabelAndTextField All the JLabel and JTextField objects.
     * @param card The CardLayout object of the center panel.
     */
    public void payProcess(AllButton allButton,AllLabelAndTextField allLabelAndTextField,CardLayout card){
        progressBarPay.setMinimum(MIN_PROGRESS);
        progressBarPay.setMaximum(MAX_PROGRESS);
        progressBarPay.setValue(currentProgress);
        progressBarPay.setStringPainted(true);
        currentProgress = MIN_PROGRESS;
        new Timer(50, e -> {
            currentProgress++;
            if (currentProgress < MAX_PROGRESS){
                allButton.getPayFinish().setEnabled(false);
            }
            else if (currentProgress == MAX_PROGRESS) {
                progressBarPay.setIndeterminate(false);
                progressBarPay.setString("You have paid successfully!");
                allButton.getPayFinish().setEnabled(true);
            }
            progressBarPay.setValue(currentProgress);
        }).start();
        payWord.add(allLabelAndTextField.getPayLabel());
        payStyle.add(payWord);
        payStyle.add(progressBarPay);
        payButtonPanel.add(allButton.getPayFinish());
        payStyle.add(payButtonPanel);
        centerPanel.add(payStyle, "payStyle");
        card.show(centerPanel,"payStyle");
    }

    /**
     * This method will be called when printing, to show the printing process.
     * @param allButton All the Button objects.
     * @param allLabelAndTextField All the JLabel and JTextField objects.
     * @param card The CardLayout object of the center panel.
     */
    public void printProcess(AllButton allButton,AllLabelAndTextField allLabelAndTextField,CardLayout card){
        progressBar.setMinimum(MIN_PROGRESS);
        progressBar.setMaximum(MAX_PROGRESS);
        progressBar.setValue(currentProgress);
        progressBar.setStringPainted(true);
        currentProgress = MIN_PROGRESS;

        new Timer(50, e -> {
            currentProgress++;
            if (currentProgress < MAX_PROGRESS){
                allButton.getPrintFinish().setEnabled(false);
            }
            else if (currentProgress == MAX_PROGRESS) {
                progressBar.setIndeterminate(false);
//                    progressBar.setString("Finish");
                allButton.getPrintFinish().setEnabled(true);
            }
            progressBar.setValue(currentProgress);
        }).start();
        printWord.add(allLabelAndTextField.getPrintLabel());
        printStyle.add(printWord);
        printStyle.add(progressBar);
        printButtonPanel.add(allButton.getPrintFinish());
        printStyle.add(printButtonPanel);
        card.show(centerPanel,"printStyle");
    }
}
